#ifndef SINGLETON_H_
#define SINGLETON_H_

#include <cassert>

namespace physicsworks {

/**
 * Implementation of the singleton pattern.
 * This singleton is based on Brian van der Beek's one.
 */
template<class T> class Singleton
{
public:
	static T* instance() {
		if (inst == 0) inst = new T;
		assert(inst != 0);
		return inst;
	}
	
	static void destroy() {
		delete inst;
		inst = 0;
	}
private:
	static T* inst;

protected:
	Singleton() {}
	~Singleton() {}
};

template<class T> T* Singleton<T>::inst = 0;

}

#endif /*SINGLETON_H_*/
